//
//  ChatList.swift
//  JiaoZiTaxi
//
//  Created by Hu Gang on 2022/10/12.
//

import SwiftUI

struct ChatList: View {
  @State private var chats: [Chat] = []

    var body: some View {
      ScrollView {
        LazyVStack(spacing: 0) {
          ForEach(chats) { chat in
            NavigationLink(destination: ChatView(chat: chat)) {
              ChatRow(chat: chat)
            }
            Separtor().padding(.leading,76)
          }
        }
        .background(Color("cell"))
      }
      .onAppear(perform: load)
    }

  func load() {
    guard chats.isEmpty else { return }
    chats = Chat.all
  }
}

struct ChatList_Previews: PreviewProvider {
    static var previews: some View {
      NavigationView {
        ChatList()
          .navigationBarTitle("客服微信", displayMode: .inline)
      }
    }
}
